package com.zhongzhi.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhongzhi.service.ComputersService;
import com.zhongzhi.service.EquipmentService;
import com.zhongzhi.springboot.pojo.Computers;
import com.zhongzhi.springboot.pojo.Equipment;
import com.zhongzhi.util.Bo;
import com.zhongzhi.util.JsonResult;

@RestController
@RequestMapping("/computers/")
public class ComputersController {

	@Autowired
	private ComputersService computersService;

	//1:增加计算机
	@RequestMapping("insert")
	public JsonResult insert(Computers computers) {
		Bo bo = computersService.insert(computers);
		return new JsonResult(bo.getMistake(),bo.getMessage(),bo.getSize(),bo.getObject());
	}
	//2:修改计算机
	@RequestMapping("update")
	public JsonResult update(Computers computers) {
		Bo bo = computersService.update(computers);
		return new JsonResult(bo.getMistake(),bo.getMessage(),bo.getSize(),bo.getObject());
	}

	//3:删除计算机(如果计算机有者通道,则不能删除)
	@RequestMapping("delete")
	public JsonResult delete(Integer id) {
		Bo bo = computersService.delete(id);
		return new JsonResult(bo.getMistake(),bo.getMessage(),bo.getSize(),bo.getObject());
	}
	//4:查询全部计算机
	@RequestMapping("select")
	public JsonResult select(Integer pages,Integer line) {
		Bo bo = computersService.select(pages,line);
		return new JsonResult(bo.getMistake(),bo.getMessage(),bo.getSize(),bo.getObject());
	}

	//5:查询全部计算机总数
	@RequestMapping("selectSize")
	public JsonResult selectSize() {
		Bo bo = computersService.selectSize();
		return new JsonResult(bo.getMistake(),bo.getMessage(),bo.getSize(),bo.getObject());
	}
	//6:查询计算机(根据id查询)
	@RequestMapping("selectById")
	public JsonResult selectById(Integer id) {
		Bo bo = computersService.selectById(id);
		return new JsonResult(bo.getMistake(),bo.getMessage(),bo.getSize(),bo.getObject());
	}

	//7:根据计算机站号查询
	@RequestMapping("selectByComputers")
	public JsonResult selectByComputers(String computers) {
		Bo bo = computersService.selectByComputers(computers);
		return new JsonResult(bo.getMistake(),bo.getMessage(),bo.getSize(),bo.getObject());
	}


	//8:增加计算机
	@RequestMapping("webinsert")
	public JsonResult webinsert(Computers computers) {
		System.out.println(computers);
		Bo bo = computersService.webinsert(computers);
		return new JsonResult(bo.getMistake(),bo.getMessage(),bo.getSize(),bo.getObject());
	}
	//9:修改计算机
	@RequestMapping("webupdate")
	public JsonResult webupdate(Computers computers) {
		Bo bo = computersService.webupdate(computers);
		return new JsonResult(bo.getMistake(),bo.getMessage(),bo.getSize(),bo.getObject());
	}

	//10:删除计算机(如果计算机有者通道,则不能删除)
	@RequestMapping("webdelete")
	public JsonResult webdelete(Integer id) {
		Bo bo = computersService.webdelete(id);
		return new JsonResult(bo.getMistake(),bo.getMessage(),bo.getSize(),bo.getObject());
	}
	//11:查询全部计算机
	@RequestMapping("webselect")
	public JsonResult webselect() {
		Bo bo = computersService.webselect();
		return new JsonResult(bo.getMistake(),bo.getMessage(),bo.getSize(),bo.getObject());
	}
}
